using UnityEngine;

namespace Script.StateMachine
{
    public class ReactState:IState
    {
        private FSM manager;
        private Parameter _parameter;
        private AnimatorStateInfo info;//动画进度
        public ReactState(FSM manager)
        {
            this.manager = manager;
            _parameter = manager.parameter;
        }

        public void OnEnter()
        {
            manager.animator.Play("React");
        }
        public void OnUpdate()
        {
            manager.Flip(_parameter.playerTrans);
            
            if (_parameter.isHit)
            {
                manager.TransitionState(StateType.Hit);
            }
            
            //当反应动画播放完毕后，切换追击动画
            info = manager.animator.GetCurrentAnimatorStateInfo(0);
            if (info.normalizedTime>0.95)
            {
                manager.TransitionState(StateType.Chase);
            }
        }
        public void OnExit()
        {
        }
    }
}